﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace DNEL.Extensions
{
    /// <summary>
    /// 
    /// </summary>
    internal static class Helper
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="HashType"></param>
        /// <returns></returns>
        internal static byte[] GetHash(string input, HashAlgorithm HashType)
        {
            byte[] inputBytes = Encoding.Default.GetBytes(input);
            
            switch (HashType)
            {
                case HashAlgorithm.MD5:
                    return MD5.Create().ComputeHash(inputBytes);

                case HashAlgorithm.SHA1:
                    return SHA1.Create().ComputeHash(inputBytes);

                case HashAlgorithm.SHA256:
                    return SHA256.Create().ComputeHash(inputBytes);

                case HashAlgorithm.SHA384:
                    return SHA384.Create().ComputeHash(inputBytes);

                case HashAlgorithm.SHA512:
                    return SHA512.Create().ComputeHash(inputBytes);

                case HashAlgorithm.RIPEMD160:
                    return RIPEMD160.Create().ComputeHash(inputBytes);

                default:
                    return inputBytes;
            }
        }
    }
}
